package com.iflytek.exam.service.impl;

import java.util.List;

import com.iflytek.common.core.domain.AjaxResult;
import com.iflytek.common.utils.DateUtils;
import com.iflytek.exam.domain.ExamSet;
import com.iflytek.exam.mapper.ExamSetMapper;
import com.iflytek.exam.service.IExamSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iflytek.exam.mapper.ExamGradeMapper;
import com.iflytek.exam.domain.ExamGrade;
import com.iflytek.exam.service.IExamGradeService;

/**
 * 试卷成绩Service业务层处理
 * 
 * @author KK
 * @date 2024-07-08
 */
@Service
public class ExamGradeServiceImpl implements IExamGradeService 
{
    @Autowired
    private ExamGradeMapper examGradeMapper;

    @Autowired
    private ExamSetMapper examSetMapper;
    /**
     * 查询试卷成绩
     * 
     * @param id 试卷成绩主键
     * @return 试卷成绩
     */
    @Override
    public ExamGrade selectExamGradeById(Long id)
    {
        return examGradeMapper.selectExamGradeById(id);
    }

    /**
     * 查询试卷成绩列表
     * 
     * @param examGrade 试卷成绩
     * @return 试卷成绩
     */
    @Override
    public List<ExamGrade> selectExamGradeList(ExamGrade examGrade)
    {
        return examGradeMapper.selectExamGradeList(examGrade);
    }

    /**
     * 新增试卷成绩
     * 
     * @param examGrade 试卷成绩
     * @return 结果
     */
    @Override
    public int insertExamGrade(ExamGrade examGrade)
    {
        examGrade.setCreateTime(DateUtils.getNowDate());
        return examGradeMapper.insertExamGrade(examGrade);
    }

    /**
     * 修改试卷成绩
     * 
     * @param examGrade 试卷成绩
     * @return 结果
     */
    @Override
    public int updateExamGrade(ExamGrade examGrade)
    {
        return examGradeMapper.updateExamGrade(examGrade);
    }

    /**
     * 批量删除试卷成绩
     * 
     * @param ids 需要删除的试卷成绩主键
     * @return 结果
     */
    @Override
    public int deleteExamGradeByIds(Long[] ids)
    {
        return examGradeMapper.deleteExamGradeByIds(ids);
    }

    /**
     * 删除试卷成绩信息
     * 
     * @param id 试卷成绩主键
     * @return 结果
     */
    @Override
    public int deleteExamGradeById(Long id)
    {
        return examGradeMapper.deleteExamGradeById(id);
    }

    @Override
    public AjaxResult getInfo(Long id) {
        ExamGrade examGrade = this.selectExamGradeById(id);
        ExamSet examSet = examSetMapper.selectExamSetByExamId(examGrade.getExamId());
        if (null != examSet){
            if (examSet.getIsLook() == 0){
                return AjaxResult.warn("该考试不允许查看!");
            }
        }
        return AjaxResult.success(examGrade);
    }

    @Override
    public ExamGrade selectExamGradeByExamIdAndUserId(Long examId, Long userId) {
        return examGradeMapper.selectExamGradeByExamIdAndUserId(examId, userId);
    }


    @Override
    public void deleteExamGradeByExamIdAndUserId(Long examId, Long userId) {
        examGradeMapper.deleteExamGradeByExamIdAndUserId(examId, userId);
    }


}
